﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrmHotel
{
    public partial class FrmGengHuan : Form
    {
        public FrmGengHuan()
        {
            InitializeComponent();
        }
        public int id;// //接收主菜单的房间号
        public int ih;// //接收选择窗口的房间号
       
        private void FrmGengHuan_Load(object sender, EventArgs e)
        {
            ShowSata(); 
        }
        public void ShowSata()
        {
            string sql = string.Format("select r.RmId,c.CeName,m.RoomName,m.RoomMoney from RoomInfo r,CetaeInfo c,Room m where c.CeFangHao=r.RmId and r.RmRoom=m.RoomId and r.RmId={0}", id);
            SqlDataReader reader = DBHelper.SelectMore(sql);
            if (reader.Read())
            {
                this.label3.Text = reader["RmId"].ToString();
                this.labelname.Text = reader["CeName"].ToString();
                this.labelClass.Text = reader["RoomName"].ToString();
                this.labelmoney.Text = reader["RoomMoney"].ToString();
            }
            reader.Close();
        }
        FrmXzFangjian fx = new FrmXzFangjian(); //选择房间
        private void button1_Click(object sender, EventArgs e)
        {

            fx.id = id;
            fx.ShowDialog();

            string sql = string.Format("select r.RmId,m.RoomName,m.RoomMoney from RoomInfo r,Room m where r.RmRoom=m.RoomId  and r.RmId={0}", fx.ih);
            SqlDataReader reader = DBHelper.SelectMore(sql);
            while(reader.Read())
            {
                this.label4.Text = reader["RmId"].ToString();
                this.label6.Text = reader["RoomName"].ToString();
                this.label5.Text = reader["RoomMoney"].ToString();
            }
            reader.Close();
            if (fx.ih!=0)
            {
                BoinColor();
            }
        }
        public void BoinColor()
        {
            this.panel5.BackColor = Color.FromArgb(91, 188, 32);
            this.label4.BackColor = Color.FromArgb(91, 188, 32);
            this.button1.BackColor = Color.FromArgb(229, 234, 237);
            this.label6.BackColor = Color.FromArgb(229, 234, 237);
            this.label5.BackColor = Color.FromArgb(229, 234, 237);
            this.button1.Text = string.Empty;
        }
        string lbl_1 = "";
        string lbl_2 = "";
        string lbl_5 = "";
        string lbl_3 = "";
        string lbl_4 = "";
        string lbl_6 = "";
        string lbl_7 = "";
        string lbl_8 = "";
        string lbl_9 = "";
        string lbl_10 = "";
        string lbl_11 = "";
        string lbl_12 = "";
        string lbl_13 = "";
        string lbl_14 = "";
        string lbl_16 = "";
        string lbl_17 = "";
        private void button2_Click_1(object sender, EventArgs e)
        {
          

            if (fx.ih == 0)
            {
                MessageBox.Show("请选择一间房间！","提示信息！");
                return;
            }
            string sql = string.Format(@"select * from Room o,CetaeInfo c,checkInfo h where h.Ckname=c.CeId and c.CeFangHao={0}", id);
          
           SqlDataReader reader = DBHelper.SelectMore(sql);
           while (reader.Read())
           {
               lbl_1 = reader["CeFangHao"].ToString();
               lbl_2 = reader["CeName"].ToString();
               lbl_5 = reader["CeSex"].ToString();
               lbl_3 = reader["CeAge"].ToString();
               lbl_4 = reader["CetaeClass"].ToString();
               lbl_6 = reader["CeHao"].ToString();
               lbl_7 = reader["CePhone"].ToString();
               lbl_8 = reader["CeAddress"].ToString();
               lbl_9 = reader["CeCut"].ToString();
               lbl_10 = reader["CeXing"].ToString();

               lbl_11 = reader["Ckname"].ToString();
               lbl_12 = reader["CKCin"].ToString();
               lbl_13 = reader["CKYong"].ToString();
               lbl_14 = reader["CKXfei"].ToString();
               lbl_16 = reader["CKPay"].ToString();
               lbl_17 = reader["CKState"].ToString();
           }
           reader.Close();
           lbl_Sata();

        }
        public void lbl_Sata()
        {
            string q = string.Format("select CKXfei from CetaeInfo c,checkInfo k,RoomInfo r where k.Ckname=c.CeId and r.RmId=c.CeFangHao and r.RmId={0}", id);
            int zong = Convert.ToInt32(DBHelper.SelectOne(q));

            string sql = string.Format(@"update CetaeInfo set  CeFangHao={0} where CeHao='{1}' ", fx.ih, lbl_6);
            int Z2 = Convert.ToInt32(DBHelper.ExecuteUpdate(sql));
            string sqls = string.Format("update RoomInfo set RmState=4 where RmId={0}",id);
            int s1 = DBHelper.ExecuteUpdate(sqls);
            string sqls1 = string.Format("update RoomInfo set RmState=3 where RmId={0}", fx.ih);
            int s2 = DBHelper.ExecuteUpdate(sqls1);

                if (s1 > 0&& s2>0)
                {
                    //string q1 = string.Format("select RoomMoney from RoomInfo r,Room m where r.RmRoom=m.RoomId and RmId={0}", fx.ih);
                    //int money = Convert.ToInt32(DBHelper.SelectOne(q1));
                    //decimal he = zong+money;
                    //string gai = string.Format("update checkInfo set CKXfei={0} where CKCin='{1}'",he, lbl_12);
                    //int ok=DBHelper.ExecuteUpdate(gai);
                    //if (ok>0)
                    //{
                        MessageBox.Show("更换房间成功！", "提示信息！");
                        string sql1 = String.Format("update  Consume set CsoRoom={0} where CsoRoom={1}", Class1.fangjian, id);
                        int a = DBHelper.ExecuteUpdate(sql1);
                        this.Close();
                    //}
                    //else
                    //{
                    //    MessageBox.Show("更换失败！", "提示信息！");
                    //}
                }
                else
                {
                    MessageBox.Show("更换失败00！", "提示信息！");
                }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
